package com.source.sys.mapper;

import com.source.sys.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ZZF
 * @since 2021-02-08
 */
public interface UserMapper extends BaseMapper<User> {
    /**
     * 逻辑删除
     * @param userId
     * @return
     */
    @Update("update sys_user set isDelete = 1 where isDelete = 0 and userId = #{userId}")
    int deleteLogic(@Param("userId") String userId);

    /**
     * 修改用户密码
     * @param loginName
     * @param password
     * @return
     */
    @Update("update sys_user set password = #{password} where loginName = #{loginName}")
    int updateLoginNameAndPwd(@Param("loginName") String loginName,@Param("password") String password);

    @Select("SELECT su.* FROM sys_user su WHERE su.userId IN (SELECT userId FROM sys_user_role sur WHERE roleId = #{roleId})")
    List<User> findByRoleId(String roleId);

    /**
     * 根据账号获取salt值
     * @param loginName
     * @return
     */
    @Select("select salt from sys_user where loginName = #{loginName}")
    String getSaltByLoginName(@Param("loginName") String loginName);
}
